package la.iok.hzsvn.lewin.movie.cloud.service;

import la.iok.hzsvn.lewin.movie.cloud.model.PhoneCode;
import org.springframework.stereotype.Service;

@Service
public class PhoneCodeGeneratorImpl implements PhoneCodeGenerator{
    @Override
    public PhoneCode generateCode() {
        String code = String.valueOf(Math.random()).substring(2,8);
        return new PhoneCode(code);
    }

    @Override
    public PhoneCode fastGenerateCode() {
        int v = (int) ((Math.random()*9 + 1)*Math.pow(10,5));
        return new PhoneCode(String.valueOf(v));
    }

    @Override
    public String fastGenerateCode(int length) {
        int v = (int) ((Math.random()*9 + 1)*Math.pow(10,length-1));
        return String.valueOf(v);
    }
}
